package com.chengjue.transaction.learn.nio;

import lombok.extern.slf4j.Slf4j;

import java.nio.IntBuffer;

/**
 * 描述:
 * NIO buffer基础学习
 * @author Kipeng Huang
 * @create 2018-03-04 下午3:44
 */
@Slf4j
public class LearnBuffer {
	public static void main(String[] args) {
		IntBuffer buffer = IntBuffer.allocate(20);
		log.info("初始化后：position:{},limit:{},capacity:{}",buffer.position(),buffer.limit(),buffer.capacity());

		//开始写入数据
		buffer.put(1);
		buffer.put(2);
		//插入数据后的属性
		log.info("插入数据后的属性：position:{},limit:{},capacity:{}",buffer.position(),buffer.limit(),buffer.capacity());

		//开始读取数据
		buffer.flip();
		log.info("模式切换后的属性：position:{},limit:{},capacity:{}",buffer.position(),buffer.limit(),buffer.capacity());
		int i = buffer.get();
		//读取数据后的属性
		log.info("读取数据后的属性：position:{},limit:{},capacity:{}",buffer.position(),buffer.limit(),buffer.capacity());

		//再次插入数据
		buffer.put(3);
		//插入数据后的属性
		log.info("再次插入数据后的属性：position:{},limit:{},capacity:{}",buffer.position(),buffer.limit(),buffer.capacity());

	}
}
